package com.jr.service.lmpl;

import com.jr.entry.BookInfo;
import com.jr.entry.PageDto;
import com.jr.mapper.BookInfoMapper;
import com.jr.pojo.util;
import com.jr.service.BookInfoService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class BookInfoServicelmpl implements BookInfoService {
    @Autowired
    private BookInfoMapper bookInfoMapper;
    @Override
    public List<BookInfo> selectbook(BookInfo bookInfo) {

        return bookInfoMapper.selectBookbyInformation(bookInfo);
    }


    @Override
    public List<BookInfo> selectAllbook() {

        return bookInfoMapper.selectAllbook();
    }

    @Override
    public boolean deletebook(Integer id) {
        return bookInfoMapper.deletebook(id)>0?true:false;
    }

    @Override
    public boolean addbooks(util util) {
        return bookInfoMapper.addbook(util)>0?true:false;
    }

    @Override
    public PageDto<BookInfo> getbooks(int page, int size) {
        PageRequest pageable=PageRequest.of(page - 1, size);
        System.out.println(page);
        System.out.println(size);
        int offset = (int) pageable.getOffset();
        int pageSize = pageable.getPageSize() ;
        int size1 = bookInfoMapper.selectAllbook().size();
        System.out.println(offset);
        System.out.println(pageSize);
        List<BookInfo> bookInfos = bookInfoMapper.selectAllbooks(offset, pageSize);

        PageDto<BookInfo> bookInfoPageDto=new PageDto<>();
        bookInfoPageDto.setContent(bookInfos);
        bookInfoPageDto.setTotalPages(size1);
        return bookInfoPageDto;
    }


}
